package day10;

import java.util.Scanner;

public class Code {
    public static void main(String[] args){
        boolean b=true;
        int i=1;
        while (b&&i<=3){
            CodeCheck codeCheck=new CodeCheck();
            b=codeCheck.Check();
            System.out.println("已经输入"+i+"次了");
            i++;
        }
    }
}
class GetCode{
    String index = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    String Code(){
        int i=(int)(Math.random()*62);
        return String.valueOf(index.charAt(i));
    }
    String setCode(){
        StringBuilder code=new StringBuilder();
        GetCode getCode=new GetCode();
        for(int i=0;i<4;i++){
            code.append(getCode.Code());
        }
        return String.valueOf(code);
    }
}
class CodeCheck{
    GetCode getCode=new GetCode();
    String code=getCode.setCode();//code为验证码
    boolean Check(){
        boolean b=true;
        System.out.println(code);
        Scanner scanner=new Scanner(System.in);
        String str=scanner.next();
        String code1=str.toLowerCase();
        if(code1.equals(code.toLowerCase())){
            System.out.println("验证码正确");
            System.exit(0);
        }
        else{
            System.out.println("验证码输入错误");
        }
        return b;
    }
}